package com.pmy.service;

import com.pmy.dao.BillMapper;
import com.pmy.pojo.Bill;
import com.pmy.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service(value = "BillServiceImpl")
public class BillServiceImpl implements BillService {
    @Autowired
    BillMapper billMapper;

    @Override
    public List<Bill> queryAll(String productName, String proName, String isPayment, int currentPageNo, int pageSize) {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("productName",productName);
        map.put("proName",proName);
        map.put("isPayment",isPayment);
        map.put("currentPageNo",currentPageNo);
        map.put("pageSize",pageSize);
        List<Bill> bills = billMapper.queryAll(map);
        return bills;
    }

    @Override
    public int getBillCount(String productName, String proName, String isPayment) {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("productName",productName);
        map.put("proName",proName);
        map.put("isPayment",isPayment);
        int billCount = billMapper.getBillCount(map);
        return billCount;
    }

    @Override
    public Bill getBillById(int id) {
        return billMapper.getBillById(id);
    }

    @Override
    public int addBill(Bill bill) {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("billCode",bill.getBillCode());
        map.put("productName",bill.getProductName());
        map.put("productDesc",bill.getProductDesc());
        map.put("productUnit",bill.getProductUnit());
        map.put("productCount",bill.getProductCount());
        map.put("totalPrice",bill.getTotalPrice());
        map.put("isPayment",bill.getIsPayment());
        map.put("providerId",bill.getProviderId());

        int addBill = billMapper.addBill(map);

        return addBill;
    }

    @Override
    public int deleteBillById(int id) {
        return billMapper.deleteBillById(id);
    }

    @Override
    public int updateBillById(Bill bill) {
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("id",bill.getId());
        map.put("billCode",bill.getBillCode());
        map.put("productName",bill.getProductName());
        map.put("productDesc",bill.getProductDesc());
        map.put("productUnit",bill.getProductUnit());
        map.put("productCount",bill.getProductCount());
        map.put("totalPrice",bill.getTotalPrice());
        map.put("isPayment",bill.getIsPayment());
        map.put("providerId",bill.getProviderId());

        int billById = billMapper.updateBillById(map);
        return billById;
    }
}
